#include <sys_config.h>
#include <types.h>
#include <basic_types.h>
#include <mediatypes.h>
#include <api/libc/printf.h>
#include <api/libc/string.h>
#include <osal/osal.h>

#if 0
typedef char CHAR, *PCHAR ;
typedef unsigned short  WCHAR;
typedef WCHAR*          PWCHAR;
typedef const WCHAR*    PCWCHAR;

typedef char*           PSTR;
typedef const char*     PCSTR;
typedef WCHAR*          PWSTR;
typedef const WCHAR*    PCWSTR;
#endif

#define ComMemCopy  ali_memcpy
#define ComMemCmp   ali_memcmp
#define ComMemMove  ali_memmove
#define ComStrCopy  ali_strcpy
#define ComStrCmp(cmp1, cmp2)   (!ali_strcmp((UINT8 *)(cmp1), (UINT8 *)(cmp2)))
#define ComStrLen   ali_strlen
#define ComMemSet   ali_memset
#define ComMemCopy3 ali_memcpy
#define ComStrCat	strcat

#define UDG_PRINTF  libc_printf
#define DBG_DUMP_DATA               0
#define DBG_PRINT_WSTRING           0
#define DBG_DUMP_BITMAP             0
#define DBG_TRACE_EIT_EVENT         0
#ifdef DISABLE_PRINTF
#define DBG_PRINT_MEMORY_LAYOUT     0
#else
#define DBG_PRINT_MEMORY_LAYOUT     1
#endif
#define DBG_COUNTRY_BAND            0
#define DBG_WATCH_POINT             0

#if DBG_DUMP_DATA
void dump_data(BYTE *lpBuf, DWORD length, char *name)
{
	int i, j = 0, k;
	char label[9], ch;
	for(i=0; name && name[i] && i<8; i++)
		label[i] = name[i];
	for(; i<8; i++)
		label[i] = ' ';
	label[8] = 0;
	UDG_PRINTF("\n %s |  0  1  2  3  4  5  6  7   8  9  A  B  C  D  E  F |\n", label);
	UDG_PRINTF("----------|--------------------------------------------------|------------------\n");
//	UDG_PRINTF(" 00000000 | 00 11 22 33 44 55 66 77  88 99 AA BB CC DD EE FF | 123456789ABCDEF\n");
	for(i=0; i<length/16; i++)
	{
		j = i*16;
//		UDG_PRINTF(" %08x | ", j);
//		for(k=0; k<8; k++)
//			UDG_PRINTF("%02x ", lpBuf[j+k]);
//		for(; k<16; k++)
//			UDG_PRINTF(" %02x", lpBuf[j+k]);
//		UDG_PRINTF(" | ");
		UDG_PRINTF(" %08x | %02x %02x %02x %02x %02x %02x %02x %02x  %02x %02x %02x %02x %02x %02x %02x %02x | ", 
					(j), lpBuf[j], lpBuf[j+1], lpBuf[j+2], lpBuf[j+3], 
					     lpBuf[j+4], lpBuf[j+5], lpBuf[j+6], lpBuf[j+7], 
					     lpBuf[j+8], lpBuf[j+9], lpBuf[j+10], lpBuf[j+11], 
					     lpBuf[j+12], lpBuf[j+13], lpBuf[j+14], lpBuf[j+15]);
		for(k=0; k<16; k++, j++)
		{
			if((BYTE)lpBuf[j] < 0x20 || (BYTE)lpBuf[j] > 0x7E)
				ch = '.';
			else
				ch = lpBuf[j];
			UDG_PRINTF("%c", ch);
		}
		UDG_PRINTF("\n");
	}
	if(length%16)
	{
		UDG_PRINTF(" %08x |", j);
		for(i=0; i<length%16 && i<8; i++)
			UDG_PRINTF(" %02x", lpBuf[j+i]);
		UDG_PRINTF(" ");
		if(length%16 >= 8)
		{
			for(;i<length%16; i++)
				UDG_PRINTF(" %02x", lpBuf[j+i]);
		}
		for(;i<16;i++)
			UDG_PRINTF("   ");
		UDG_PRINTF(" | ");
		for(i=0; i<length%16; i++)
		{
			if((BYTE)lpBuf[j+i] < 0x20 || (BYTE)lpBuf[j+i] > 0x7E)
				ch = '.';
			else
				ch = lpBuf[j+i];
			UDG_PRINTF("%c", ch);
		}
		UDG_PRINTF("\n");
	}
	UDG_PRINTF("--------------------------------------------------------------------------------\n");
}
#endif

#if DBG_PRINT_WSTRING
void dbg_print_wstring(PCWSTR pStr)
{
    while(*pStr)
    {
        if(*pStr>=0x20 && *pStr<=0x7E)
            UDG_PRINTF("%c", *pStr);
        else
            UDG_PRINTF("?");
        pStr++;
    }
    UDG_PRINTF("\n");
}
#endif

#if DBG_DUMP_BITMAP
void dump_bitmap(UINT8 *pBuf, INT16 uLength, INT16 uWidth, INT16 uHeight, UINT8 uFactor)
{
    INT16 i, j;
    UINT8 uColor;
    UINT32 uOffset = uLength>>uFactor;

#if 1
    if(uWidth%4 || uFactor)
    {
        UDG_PRINTF("%s: Invalid Format\n", __FUNCTION__);
        return;
    }
    for(i=0; i<uHeight; i++)
    {
        for(j=i*uWidth; j<(i+1)*uWidth; j+=4)
        {
            UDG_PRINTF("%02x%02x%02x%02x\n", pBuf[j+3], pBuf[j+2], pBuf[j+1], pBuf[j]);
        }
    }
#else
    UDG_PRINTF("   |");
    for(i=0; i<uWidth; i++)
	    UDG_PRINTF(" %02d", i);
    UDG_PRINTF("\n");
    UDG_PRINTF("---|");
    for(i=0; i<uWidth; i++)
        UDG_PRINTF("---");
    UDG_PRINTF("\n");

    for(i=0; i<uHeight; i++)
    {
        UDG_PRINTF("%02d |", i);
        for(j=0; j<uWidth; j++)
        {
            uColor = pBuf[uOffset+(j>>uFactor)];
            if(uFactor)
            {
                if(!(j&0x01))
                    uColor >>= 4;
                uColor &= 0x0F;
            }
            UDG_PRINTF(" %02x", uColor);
        }
        UDG_PRINTF("\n");
		uOffset += (uLength>>uFactor);
    }
#endif
}
#endif

#if DBG_TRACE_EIT_EVENT
UINT32 dbg_total_size;
static void trace_eit_event(eit_event_info_t *ep)
{
    UDG_PRINTF("eit_event_info tracing: ep=0x%x, size=%d\n", ep, dbg_total_size);
    if(ep->eit_ct_desc)
        UDG_PRINTF("    eit_ct_desc=0x%x\n", ep->eit_ct_desc);
    if(ep->eit_pr_desc)
        UDG_PRINTF("    eit_pr_desc=0x%x\n", ep->eit_pr_desc);

    int i;
    if(ep->eit_sht_desc)
    {
        UDG_PRINTF("    eit_sht_desc=0x%x\n", ep->eit_sht_desc);
        UDG_PRINTF("       event_name=0x%x\n", ep->eit_sht_desc->event_name);
        UDG_PRINTF("       text_desc=0x%x\n", ep->eit_sht_desc->text_desc);
        eit_short_desc_t *psht = ep->eit_sht_desc->next;
        i = 0;
        while(psht)
        {
            UDG_PRINTF("    [%d]next=0x%x\n", i++, psht);
            UDG_PRINTF("       event_name=0x%x\n", psht->event_name);
            UDG_PRINTF("       text_desc=0x%x\n", psht->text_desc);
            psht = psht->next;
        }
    }

    if(ep->eit_ext_desc)
    {
        UDG_PRINTF("    eit_ext_desc=0x%x\n", ep->eit_ext_desc);
        UDG_PRINTF("       text_char=0x%x\n", ep->eit_ext_desc->text_char);
        eit_ext_desc_t *pext = ep->eit_ext_desc->next;
        i = 0;
        while(pext)
        {
            UDG_PRINTF("    [%d]next=0x%x\n", ++i, pext);
            UDG_PRINTF("       text_char=0x%x\n", pext->text_char);
            pext = pext->next;
        }
    }
}
#endif

#if DBG_PRINT_MEMORY_LAYOUT
static void Ul2HexStr(DWORD Val, PCHAR Str, BOOL fIgnoreZero, BOOL fCapital)
{
    int i, j;
    char num, chr = 'A';
    BOOL fNonZero = FALSE;

    if(!fCapital)
        chr = 'a';
    for(i=0, j=0; i<8; i++)
    {
        num = (Val >> ((7-i)*4)) & 0x0F;
        if(!fNonZero && fIgnoreZero)
        {
            if(!num)
                continue;
            else
                fNonZero = TRUE;
        }
        if(num < 10)
            Str[j++] = '0' + num;
        else
            Str[j++] = chr + num - 0x0A;
    }
    if(!j)
        Str[j++] = (char)'0';
    Str[j] = 0;
}

static void print_buffer_range(DWORD Address, DWORD Size, char *name)
{
#define PRINT_NUM_ITEM  2
#define CONTENT_RESERVED_LEN    12
#define REPLACE_START_POS       (CONTENT_RESERVED_LEN-1)
    char *szTop     = "+------------------------------+";
    char *szContent = "          |                              |";
    char OutBuf[64], TempBuf[30], NumBuf[10];
    int i, j, len, output_len, start_pos;

    Size &= 0x0fffffff;
#ifdef _S3811_
    DWORD Number[PRINT_NUM_ITEM] = {Size, (Address)};
#else
    DWORD Number[PRINT_NUM_ITEM] = {Size, (Address+Size)};
#endif
    char *szPrefix[PRINT_NUM_ITEM] = {"Size=0x", "Next=0x"};

    if(NULL == name)
    {
        UDG_PRINTF("          %s\n", szTop);
        return;
    }

#ifdef _S3811_
    UDG_PRINTF("0x%08x", Address+Size);
#else
    UDG_PRINTF("0x%08x", Address);
#endif
    UDG_PRINTF("%s\n", szTop);
    output_len = ComStrLen(szContent) - CONTENT_RESERVED_LEN;

    ComStrCopy(OutBuf, szContent);    
    len = ComStrLen(name);
    if(len > output_len)
        len = output_len;
    start_pos = REPLACE_START_POS + (output_len - len)/2;
    for(i=0; i<len; i++)
        OutBuf[i+start_pos] = name[i];
    UDG_PRINTF("%s\n", OutBuf);

    for(j=0; j<PRINT_NUM_ITEM; j++)
    {
        ComStrCopy(OutBuf, szContent);
        ComStrCopy(TempBuf, szPrefix[j]);
        Ul2HexStr(Number[j], NumBuf, FALSE, FALSE);
        ComStrCat(TempBuf, NumBuf);
        len = ComStrLen(TempBuf);
        if(len > output_len)
            len = output_len;
        start_pos = REPLACE_START_POS + (output_len - len)/2;
        for(i=0; i<len; i++)
            OutBuf[i+start_pos] = TempBuf[i];
        UDG_PRINTF("%s\n", OutBuf);
    }
}

#ifdef _S3811_
void print_memory_layout()
{
	extern UINT heap_start;
    //UDG_PRINTF("\n======== Memory Layout ==========\n");
#ifndef __MM_HIGHEST_ADDR
    #define __MM_HIGHEST_ADDR       0xa8000000
    #define __MM_VOID_BUFFER_ADDR   __MM_HIGHEST_ADDR - 0x100000
#endif

	#define VOID_LEN (__MM_HIGHEST_ADDR-__MM_VOID_BUFFER_ADDR)
    
	print_buffer_range(__MM_HIGHEST_ADDR, 0, "Total Memory");
	print_buffer_range(__MM_VOID_BUFFER_ADDR,VOID_LEN, "Void Memory");
	print_buffer_range(__MM_FB_TOP_ADDR, 0, "Frame buffer top memory");
    	print_buffer_range(__MM_VBV_START_ADDR,__MM_VBV_LEN , "VBV");
	print_buffer_range(__MM_MAF_START_ADDR,__MM_MAF_LEN , "__MM_MAF_START_ADDR ");
	print_buffer_range(__MM_FB_START_ADDR,__MM_FB_LEN , "__MM_FB_START_ADDR ");

#ifdef AVC_SUPPORT_UNIFY_MEM
	print_buffer_range(AVC_VBV_ADDR, AVC_VBV_LEN , "AVC VBV");
	print_buffer_range(AVC_CMD_QUEUE_ADDR, AVC_CMD_QUEUE_LEN, " AVC_CMD_QUEUE_ADDR");
	print_buffer_range(AVC_MB_COL_ADDR, AVC_MB_COL_LEN, " AVC_MB_COL_ADDR");
	print_buffer_range(AVC_MB_NEI_ADDR, AVC_MB_NEI_LEN, "AVC_MB_NEI_ADDR ");
	print_buffer_range(AVC_MEM_ADDR, AVC_MEM_LEN, "AVC_MB_NEI_ADDR ");
#else
	print_buffer_range(AVC_VBV_ADDR, AVC_VBV_LEN , "AVC VBV");
	print_buffer_range(AVC_FB_ADDR, AVC_FB_LEN , "AVC FB");
	print_buffer_range(AVC_DVIEW_ADDR, AVC_DVIEW_LEN , "AVC DVIEW");
	print_buffer_range(AVC_MV_ADDR, AVC_MV_LEN , "AVC MV");
	print_buffer_range(AVC_CMD_QUEUE_ADDR, AVC_CMD_QUEUE_LEN , "AVC CMD QUEUE");
	print_buffer_range(AVC_MB_COL_ADDR, AVC_MB_COL_LEN, " AVC_MB_COL_ADDR");
	print_buffer_range(AVC_MB_NEI_ADDR, AVC_MB_NEI_LEN, "AVC_MB_NEI_ADDR ");
	print_buffer_range(AVC_LAF_FLAG_BUF_ADDR, AVC_LAF_FLAG_BUF_LEN , "AVC_LAF_FLAG_BUF_ADDR");
	print_buffer_range(AVC_LAF_RW_BUF_ADDR, AVC_LAF_RW_BUF_LEN , "AVC_LAF_RW_BUF_ADDR");
#endif
	print_buffer_range(__MM_FB_BOTTOM_ADDR, 0, "__MM_FB_BOTTOM_ADDR ");

	print_buffer_range(__MM_PVR_VOB_BUFFER_ADDR, __MM_PVR_VOB_BUFFER_LEN, "VOB cache");
	print_buffer_range(__MM_AUTOSCAN_DB_BUFFER_ADDR, __MM_AUTOSCAN_DB_BUFFER_LEN, "AUTOSCAN DB ");

	print_buffer_range(__MM_DMX_AVP_START_ADDR,__MM_SI_VBV_OFFSET + __MM_DMX_DATA_LEN + __MM_DMX_AVP_LEN , "DMX AVP ");
	print_buffer_range(__MM_DMX_REC_START_ADDR,__MM_DMX_REC_LEN , "DMX_REC_Start ");
	print_buffer_range(__MM_DMX_CPU_BLK_ADDR, __MM_DMX_BLK_BUF_LEN,"__MM_DMX_CPU_BLK_ADDR");
	print_buffer_range(__MM_DMX_SEE_BLK_ADDR,__MM_DMX_BLK_BUF_LEN , "__MM_DMX_SEE_BLK_ADDR ");
	print_buffer_range(__MM_TTX_SUB_PAGE_BUF_ADDR, __MM_TTX_SUB_PAGE_LEN, "TTX_SUB_PAGE ");
	print_buffer_range(__MM_TTX_P26_NATION_BUF_ADDR,__MM_TTX_P26_NATION_LEN , " TTX_P26_NATION");
	print_buffer_range(__MM_TTX_P26_DATA_BUF_ADDR, __MM_TTX_P26_DATA_LEN, "TTX_P26_DATA_ ");
	print_buffer_range(__MM_TTX_BS_START_ADDR,__MM_TTX_BS_LEN , "__MM_TTX_BS_START_ADDR ");
	print_buffer_range(__MM_TTX_PB_START_ADDR,__MM_TTX_PB_LEN , "__MM_TTX_PB_START_ADDR ");
	print_buffer_range(__MM_EPG_BUFFER_START ,__MM_EPG_BUFFER_LEN, "EPG_BUFFER ");

	print_buffer_range(__MM_GE_START_ADDR, __MM_GE_LEN, "GE ");
	print_buffer_range(__MM_OSD_BK_ADDR2, __MM_OSD2_LEN, "OSD LAYER2 ");
	print_buffer_range(__MM_OSD_BK_ADDR1,__MM_OSD1_LEN , "OSD LAYER1 ");
	print_buffer_range(__MM_VCAP_FB_ADDR, __MM_VCAP_FB_SIZE, "__MM_VCAP_FB_ADDR ");
#ifdef OSD_VSRC_SUPPORT
	print_buffer_range(__MM_OSD_VSRC_MEM_ADDR, OSD_VSRC_MEM_MAX_SIZE, "OSD VSRC ");
#endif
	print_buffer_range(__MM_SUB_BS_START_ADDR,__MM_SUB_BS_LEN , "SUB_BS_START_ ");
	print_buffer_range(__MM_SUB_HW_DATA_ADDR,__MM_SUB_HW_DATA_LEN , "__MM_SUB_HW_DATA_ADDR ");
	print_buffer_range(__MM_SUB_PB_START_ADDR,__MM_SUB_PB_LEN , "SUB_PB_START ");
	
#if(SYS_SDRAM_SIZE == 128)
	print_buffer_range(__MM_COFDM_S3811_ISDBT_ADDR,__MM_COFDM_S3811_ISDBT_BUF_LEN , "__MM_COFDM_S3811_ISDBT_ADDR ");
#endif
#ifdef ISDBT_CC
	print_buffer_range(__MM_ISDBTCC_BS_START_ADDR,__MM_ISDBTCC_BS_LEN , "__MM_ISDBTCC_BS_START_ADDR ");
	print_buffer_range(__MM_ISDBTCC_PB_START_ADDR,__MM_ISDBTCC_PB_LEN , "__MM_ISDBTCC_PB_START_ADDR ");
	print_buffer_range(__MM_LWIP_MEM_ADDR,__MM_LWIP_MEM_LEN , "__MM_LWIP_MEM_ADDR ");
#else
	print_buffer_range(__MM_LWIP_MEM_ADDR,__MM_LWIP_MEM_LEN , "__MM_LWIP_MEM_ADDR ");
#endif
	print_buffer_range(__MM_LWIP_MEMP_ADDR, __MM_LWIP_MEMP_LEN,"__MM_LWIP_MEMP_ADDR");
	print_buffer_range(__MM_USB_START_ADDR, __MM_USB_DMA_LEN," USB_START_");
	print_buffer_range(__MM_CPU_DBG_MEM_ADDR, __MM_DBG_MEM_LEN, "CPU debug buffer ");
	
	print_buffer_range(__MM_MP_BUFFER_ADDR, __MM_MP_BUFFER_LEN, "__MM_MP_BUFFER_ADDR");

	print_buffer_range(heap_start, (__MM_HEAP_TOP_ADDR&0x0fffffff)-(heap_start&0x0fffffff), "Heap");
	print_buffer_range(0, heap_start, "Code");
	
    print_buffer_range(0, 0, NULL);
}
#else
#ifndef _USE_32M_MEM_
void print_memory_layout()
{
	extern UINT heap_start;
    //UDG_PRINTF("\n======== Memory Layout ==========\n");
#ifndef __MM_HIGHEST_ADDR
    #define __MM_HIGHEST_ADDR       0xa8000000
    #define __MM_VOID_BUFFER_ADDR   __MM_HIGHEST_ADDR - 0x100000
#endif

	#define VOID_LEN (__MM_HIGHEST_ADDR-__MM_VOID_BUFFER_ADDR)

    print_buffer_range(0, heap_start, "Code");
    print_buffer_range(heap_start, (__MM_HEAP_TOP_ADDR&0x0fffffff)-(heap_start&0x0fffffff), "Heap");

	print_buffer_range(__MM_AUTOSCAN_DB_BUFFER_ADDR, __MM_AUTOSCAN_DB_BUFFER_LEN, "AUTOSCAN DB ");
	print_buffer_range(__MM_DMX_AVP_START_ADDR,__MM_SI_VBV_OFFSET + __MM_DMX_DATA_LEN + __MM_DMX_AVP_LEN , "DMX AVP ");
	print_buffer_range(__MM_VBV_START_ADDR,__MM_VBV_LEN , "VBV");
    print_buffer_range(__MM_EPG_BUFFER_START ,__MM_EPG_BUFFER_LEN, "EPG_BUFFER ");
	print_buffer_range(__MM_USB_START_ADDR, __MM_USB_DMA_LEN," USB_START_");
    print_buffer_range(__MM_SUB_PB_START_ADDR,__MM_SUB_PB_LEN , "SUB_PB_START ");
	print_buffer_range(__MM_SUB_BS_START_ADDR,__MM_SUB_BS_LEN , "SUB_BS_START_ ");
    print_buffer_range(__MM_TTX_P26_DATA_BUF_ADDR, __MM_TTX_P26_DATA_LEN, "TTX_P26_DATA_ ");
	print_buffer_range(__MM_TTX_P26_NATION_BUF_ADDR,__MM_TTX_P26_NATION_LEN , " TTX_P26_NATION");
    print_buffer_range(__MM_TTX_SUB_PAGE_BUF_ADDR, __MM_TTX_SUB_PAGE_LEN, "TTX_SUB_PAGE ");
	print_buffer_range(__MM_TTX_PB_START_ADDR, __MM_TTX_PB_LEN, "TTX_PB_START ");
    print_buffer_range(__MM_TTX_BS_START_ADDR, __MM_TTX_BS_LEN, "TTX_BS_START ");
	print_buffer_range(__MM_DMX_REC_START_ADDR,__MM_DMX_REC_LEN , "DMX_REC_Start ");

    print_buffer_range(AVC_LAF_FLAG_BUF_ADDR, AVC_LAF_FLAG_BUF_LEN, "AVC_LAF_FLAG_BUF_ADDR ");
	print_buffer_range(AVC_LAF_RW_BUF_ADDR,AVC_LAF_RW_BUF_LEN , "AVC_LAF_RW_BUF_ADDR ");
    print_buffer_range(AVC_CMD_QUEUE_ADDR, AVC_CMD_QUEUE_LEN, " AVC_CMD_QUEUE_ADDR");
	print_buffer_range(AVC_MB_NEI_ADDR, AVC_MB_NEI_LEN, "AVC_MB_NEI_ADDR ");
    print_buffer_range(AVC_MB_COL_ADDR, AVC_MB_COL_LEN, " AVC_MB_COL_ADDR");
	print_buffer_range(AVC_MV_ADDR, AVC_MV_LEN, "AVC_MV_ADDR ");
    print_buffer_range(AVC_DVIEW_ADDR,AVC_DVIEW_LEN , "AVC_DVIEW_ADDR ");
	print_buffer_range(AVC_FB_ADDR, AVC_FB_LEN, "AVC_FB_ADDR ");
    print_buffer_range(AVC_VBV_ADDR, AVC_VBV_LEN , "AVC VBV");
	print_buffer_range(__MM_FB_TOP_ADDR, 0, "Frame buffer top memory");

//	print_buffer_range(__MM_OSD_VSRC_MEM_ADDR, OSD_VSRC_MEM_MAX_SIZE, "OSD VSRC ");
	print_buffer_range(__MM_OSD_BK_ADDR2, __MM_OSD2_LEN, "OSD LAYER2 ");
	print_buffer_range(__MM_OSD_BK_ADDR1,__MM_OSD1_LEN , "OSD LAYER1 ");
	print_buffer_range(__MM_GE_START_ADDR, __MM_GE_LEN, "GE ");
    print_buffer_range(__MM_PVR_VOB_BUFFER_ADDR, __MM_PVR_VOB_BUFFER_LEN, "VOB cache");
	print_buffer_range(__MM_VOID_BUFFER_ADDR,VOID_LEN, "Void Memory");
	print_buffer_range(__MM_HIGHEST_ADDR, 0, "Total Memory");
	
    print_buffer_range(0, 0, NULL);
}
#endif
#endif

#ifdef _SUPPORT_64M_MEM
void print_memory_layout_single()
{
	extern UINT heap_start;
    //UDG_PRINTF("\n======== Memory Layout ==========\n");

	//print_buffer_range(__MM_SHARE_BASE_ADDR,__MM_SHARED_MEM_LEN , "__MM_SHARE_BASE_ADDR ");
	print_buffer_range(__MM_HIGHEST_ADDR, 0, "Total Memory");
	print_buffer_range(__MM_VOID_BUFFER_ADDR, __MM_VOID_BUFFER_LEN , "void buffer to customer");
	libc_printf("\n\nshare memory mapping\n\n");

	print_buffer_range(__MM_VBV_START_ADDR,__MM_VBV_LEN , "__MM_VBV_START_ADDR ");
	print_buffer_range(__MM_MAF_START_ADDR,__MM_MAF_LEN , "__MM_MAF_START_ADDR ");
	print_buffer_range(__MM_FB_START_ADDR,__MM_FB_LEN , "__MM_FB_START_ADDR ");

	print_buffer_range(AVC_VBV_ADDR, AVC_VBV_LEN , "AVC VBV");
	print_buffer_range(AVC_CMD_QUEUE_ADDR, AVC_CMD_QUEUE_LEN, " AVC_CMD_QUEUE_ADDR");
	print_buffer_range(AVC_MB_COL_ADDR, AVC_MB_COL_LEN+AVC_MV_LEN, " AVC_MB_COL_ADDR");
	print_buffer_range(AVC_MB_NEI_ADDR, AVC_MB_NEI_LEN, "AVC_MB_NEI_ADDR ");
	print_buffer_range(AVC_MEM_ADDR, AVC_MEM_LEN, "AVC_MEM_ADDR ");

	print_buffer_range(__MM_DMX_AVP_START_ADDR,__MM_SI_VBV_OFFSET + __MM_DMX_DATA_LEN + __MM_DMX_AVP_LEN , "DMX AVP ");
	print_buffer_range(__MM_DMX_REC_START_ADDR, __MM_DMX_REC_LEN,"__MM_DMX_REC_START_ADDR");
	print_buffer_range(__MM_DMX_CPU_BLK_ADDR, __MM_DMX_BLK_BUF_LEN,"__MM_DMX_CPU_BLK_ADDR");

    //print_buffer_range(__MM_DMX_SEE_BLK_ADDR,__MM_DMX_BLK_BUF_LEN , "__MM_DMX_SEE_BLK_ADDR ");
	print_buffer_range(__MM_DMX_SEE_BLK_ADDR,__MM_DMX_SEE_BLK_BUF_LEN , "__MM_DMX_SEE_BLK_ADDR ");

    print_buffer_range(__MM_PVR_VOB_BUFFER_ADDR,__MM_PVR_VOB_BUFFER_LEN , "VOB cache");

	print_buffer_range(__MM_TTX_SUB_PAGE_BUF_ADDR, __MM_TTX_SUB_PAGE_LEN, "TTX_SUB_PAGE ");
	print_buffer_range(__MM_TTX_P26_NATION_BUF_ADDR,__MM_TTX_P26_NATION_LEN , " TTX_P26_NATION");
	print_buffer_range(__MM_TTX_P26_DATA_BUF_ADDR, __MM_TTX_P26_DATA_LEN, "TTX_P26_DATA_ ");
	print_buffer_range(__MM_TTX_BS_START_ADDR, __MM_TTX_BS_LEN, "TTX_BS_START ");
	print_buffer_range(__MM_TTX_PB_START_ADDR, __MM_TTX_PB_LEN, "TTX_PB_START ");

	print_buffer_range(__MM_EPG_BUFFER_START ,__MM_EPG_BUFFER_LEN, "EPG_BUFFER ");

    print_buffer_range(__MM_SUB_BS_START_ADDR,__MM_SUB_BS_LEN , "SUB_BS_START_ ");
	print_buffer_range(__MM_SUB_PB_START_ADDR,__MM_SUB_PB_LEN , "SUB_PB_START ");
    
	print_buffer_range(__MM_OSD_BK_ADDR2, __MM_OSD2_LEN, "__MM_OSD_BK_ADDR2 ");
	print_buffer_range(__MM_OSD_BK_ADDR1, __MM_OSD1_LEN, "__MM_OSD_BK_ADDR1 ");
	print_buffer_range(__MM_VCAP_FB_ADDR, __MM_VCAP_FB_SIZE, "__MM_VCAP_FB_ADDR ");
	print_buffer_range(__MM_OSD_VSRC_MEM_ADDR, OSD_VSRC_MEM_MAX_SIZE, "__MM_OSD_VSRC_MEM_ADDR ");
	//print_buffer_range(__MM_GE_START_ADDR, __MM_GE_LEN, "__MM_GE_START_ADDR ");	

#ifdef ISDBT_SUPPORT
	print_buffer_range(__MM_COFDM_S3811_ISDBT_ADDR,__MM_COFDM_S3811_ISDBT_BUF_LEN , "ISDBT_NIM_BF ");
#ifdef ISDBT_CC    
	print_buffer_range(__MM_ISDBTCC_BS_START_ADDR,__MM_ISDBTCC_BS_LEN+__MM_ISDBTCC_PB_LEN , "ISDBT_CC_BF ");
#endif	
#endif
        #ifdef NETWORK_SUPPORT
	print_buffer_range(__MM_LWIP_MEM_ADDR,__MM_LWIP_MEM_LEN , "LWIP_MEM ");
	print_buffer_range(__MM_LWIP_MEMP_ADDR,__MM_LWIP_MEMP_LEN , "LWIP_MEMP ");
        #endif

	libc_printf("\n\nmain memory mapping\n\n");
	print_buffer_range(heap_start, (__MM_HEAP_TOP_ADDR&0x0fffffff)-(heap_start&0x0fffffff), "Heap");
	print_buffer_range(0, heap_start, "Code");

	libc_printf("\n\n MP buffer\n\n");
	print_buffer_range(__MM_MP_BUFFER_ADDR,__MM_MP_BUFFER_LEN , "MM_MP_BUFFER ");


    print_buffer_range(0, 0, NULL);
	
}

#else

#ifdef _USE_32M_MEM_
void print_memory_layout_dual_32M()
{
	extern UINT heap_start;
    //UDG_PRINTF("\n======== Memory Layout ==========\n");

	libc_printf("\n\nmain memory mapping\n\n");

    print_buffer_range(0, heap_start, "Code");
    print_buffer_range(heap_start, (__MM_HEAP_TOP_ADDR&0x0fffffff)-(heap_start&0x0fffffff), "Heap");

	print_buffer_range(__MM_CPU_DBG_MEM_ADDR, __MM_DBG_MEM_LEN, "CPU debug buffer ");
	
	print_buffer_range(__MM_DCII_SUB_BS_START_ADDR, __MM_DCII_SUB_BS_LEN, "DCII");
	print_buffer_range(__MM_OSD_BK_ADDR1, __MM_OSD_LEN, "__MM_OSD_BK_ADDR1 ");
	print_buffer_range(__MM_NIM_BUFFER_ADDR, __MM_NIM_BUFFER_LEN, "nim J83B buffer ");
	print_buffer_range(__MM_DMX_CPU_BLK_ADDR, __MM_DMX_BLK_BUF_LEN,"__MM_DMX_CPU_BLK_ADDR");
	print_buffer_range(__MM_DMX_AVP_START_ADDR,__MM_SI_VBV_OFFSET + __MM_DMX_DATA_LEN + __MM_DMX_AVP_LEN , "DMX AVP ");
	print_buffer_range(__MM_PVR_VOB_BUFFER_ADDR,__MM_PVR_VOB_BUFFER_LEN , "VOB cache");

	print_buffer_range(__OTA_ADDR, __OTA_ADDR_LEN, "__OTA_ADDR ");		
	print_buffer_range(__MM_AUTOSCAN_DB_BUFFER_ADDR, __MM_AUTOSCAN_DB_BUFFER_LEN,"__MM_AUTOSCAN_DB_BUFFER_ADDR");	

	print_buffer_range(__MM_OSD_BK_ADDR3, __MM_OSD2_LEN, "__MM_OSD_BK_ADDR3 ");	
	print_buffer_range(__MM_EPG_BUFFER_START ,__MM_EPG_BUFFER_LEN, "EPG_BUFFER ");
	
    print_buffer_range(__MM_DVW_START_ADDR, __MM_DVW_LEN, "__MM_DVW_ADDR");
	print_buffer_range(__MM_FB_START_ADDR, __MM_FB_LEN, "__MM_FB_ADDR ");
	print_buffer_range(__MM_FB_TOP_ADDR, 0, "Frame buffer top memory");
	print_buffer_range(__MM_OSD_VSRC_MEM_ADDR, OSD_VSRC_MEM_MAX_SIZE, "__MM_OSD_VSRC_MEM_ADDR ");

	libc_printf("\n\nprivate memory mapping\n\n");
#ifdef DUAL_ENABLE
	print_buffer_range(__MM_SEE_DBG_MEM_ADDR,__MM_DBG_MEM_LEN , "SEE debug");
#endif
	print_buffer_range(__MM_SUBT_ATSC_SEC_ADDR,__MM_SUBT_ATSC_SEC_LEN , "SUB_ATSC_ADDR");
	print_buffer_range(__MM_SUB_PB_START_ADDR,__MM_SUB_PB_LEN , "SUB_PB_START ");
	print_buffer_range(__MM_SUB_BS_START_ADDR,__MM_SUB_BS_LEN , "SUB_BS_START_ ");
	print_buffer_range(__MM_OSD_BK_ADDR2, __MM_OSD1_LEN, "__MM_OSD_BK_ADDR2 ");
	print_buffer_range(__MM_TTX_PB_START_ADDR, __MM_TTX_PB_LEN, "TTX_PB_START ");
	print_buffer_range(__MM_TTX_BS_START_ADDR, __MM_TTX_BS_LEN, "TTX_BS_START ");
	print_buffer_range(__MM_TTX_P26_DATA_BUF_ADDR, __MM_TTX_P26_DATA_LEN, "TTX_P26_DATA_ ");
	print_buffer_range(__MM_TTX_P26_NATION_BUF_ADDR,__MM_TTX_P26_NATION_LEN , " TTX_P26_NATION");
	print_buffer_range(__MM_TTX_SUB_PAGE_BUF_ADDR, __MM_TTX_SUB_PAGE_LEN, "TTX_SUB_PAGE ");
	print_buffer_range(__MM_DMX_SEE_BLK_ADDR,__MM_DMX_BLK_BUF_LEN , "__MM_DMX_SEE_BLK_ADDR ");
	print_buffer_range(__MM_MAF_START_ADDR,__MM_MAF_LEN , "__MM_MAF_ADDR ");
	print_buffer_range(__MM_VBV_START_ADDR,__MM_VBV_LEN , "__MM_VBV_START_ADDR ");

	libc_printf("\n\nshare memory mapping\n\n");
#ifdef DUAL_ENABLE
	print_buffer_range(__MM_SHARE_BASE_ADDR,__MM_SHARED_MEM_LEN , "__MM_SHARE_BASE_ADDR ");
	print_buffer_range(__MM_VOID_BUFFER_ADDR, __MM_VOID_BUFFER_LEN , "void buffer to customer");
#endif
	print_buffer_range(__MM_HIGHEST_ADDR, 0, "Total Memory");

    print_buffer_range(0, 0, NULL);
	libc_printf("SYS_DRAM_SIZE=%d\n", SYS_SDRAM_SIZE);
}

#else
#ifdef _S3281_
void print_memory_layout_dual()
{
	extern UINT heap_start;
    //UDG_PRINTF("\n======== Memory Layout ==========\n");

	libc_printf("\n\nmain memory mapping\n\n");

    print_buffer_range(0, heap_start, "Code");
    print_buffer_range(heap_start, (__MM_HEAP_TOP_ADDR&0x0fffffff)-(heap_start&0x0fffffff), "Heap");

	print_buffer_range(__MM_CPU_DBG_MEM_ADDR, __MM_DBG_MEM_LEN, "CPU debug buffer ");
	print_buffer_range(__MM_DCII_SUB_BS_START_ADDR, __MM_DCII_SUB_BS_LEN, "DCII");
	print_buffer_range(__MM_USB_START_ADDR, __MM_USB_DMA_LEN,"USB_START_");
	print_buffer_range(__MM_LWIP_MEMP_ADDR, __MM_LWIP_MEMP_LEN,"__MM_LWIP_MEMP_ADDR");
	print_buffer_range(__MM_LWIP_MEM_ADDR, __MM_LWIP_MEM_LEN,"__MM_LWIP_MEM_ADDR");
	print_buffer_range(__MM_VCAP_FB_ADDR, __MM_VCAP_FB_SIZE, "__MM_VCAP_FB_ADDR ");
	print_buffer_range(__MM_OSD_BK_ADDR1, __MM_OSD_LEN, "__MM_OSD_BK_ADDR1 ");
	print_buffer_range(__MM_GE_START_ADDR, __MM_GE_LEN, "__MM_GE_START_ADDR ");		
	print_buffer_range(__MM_NIM_BUFFER_ADDR, __MM_NIM_BUFFER_LEN, "nim J83B buffer ");
	print_buffer_range(__MM_OSD_BK_ADDR3, __MM_OSD2_LEN, "__MM_OSD_BK_ADDR3 ");	
	print_buffer_range(__MM_EPG_BUFFER_START ,__MM_EPG_BUFFER_LEN, "EPG_BUFFER ");
	print_buffer_range(__MM_DMX_CPU_BLK_ADDR, __MM_DMX_BLK_BUF_LEN,"__MM_DMX_CPU_BLK_ADDR");
	print_buffer_range(__MM_DMX_REC_START_ADDR, __MM_DMX_REC_LEN,"__MM_DMX_REC_START_ADDR");
	print_buffer_range(__MM_DMX_AVP_START_ADDR,__MM_SI_VBV_OFFSET + __MM_DMX_DATA_LEN + __MM_DMX_AVP_LEN , "DMX AVP ");
	print_buffer_range(__MM_AUTOSCAN_DB_BUFFER_ADDR, __MM_AUTOSCAN_DB_BUFFER_LEN,"__MM_AUTOSCAN_DB_BUFFER_ADDR");	
	print_buffer_range(__MM_PVR_VOB_BUFFER_ADDR,__MM_PVR_VOB_BUFFER_LEN , "VOB cache");
	print_buffer_range(AVC_LAF_RW_BUF_ADDR,AVC_LAF_RW_BUF_LEN , "AVC_LAF_RW_BUF_ADDR ");
    print_buffer_range(AVC_MB_NEI_ADDR, AVC_MB_NEI_LEN, "AVC_MB_NEI_ADDR ");
    print_buffer_range(AVC_MB_COL_ADDR, AVC_MB_COL_LEN, " AVC_MB_COL_ADDR");
	print_buffer_range(AVC_MV_ADDR, AVC_MV_LEN, "AVC_MV_ADDR ");
    print_buffer_range(AVC_DVIEW_ADDR,AVC_DVIEW_LEN , "AVC_DVIEW_ADDR ");
	print_buffer_range(AVC_FB_ADDR, AVC_FB_LEN, "AVC_FB_ADDR ");
	print_buffer_range(__MM_FB_TOP_ADDR, 0, "Frame buffer top memory");
	print_buffer_range(__MM_OSD_VSRC_MEM_ADDR, OSD_VSRC_MEM_MAX_SIZE, "__MM_OSD_VSRC_MEM_ADDR ");

	libc_printf("\n\nprivate memory mapping\n\n");
#ifdef DUAL_ENABLE
	print_buffer_range(__MM_SEE_DBG_MEM_ADDR,__MM_DBG_MEM_LEN , "SEE debug");
#endif	
	print_buffer_range(__MM_SUBT_ATSC_SEC_ADDR,__MM_SUBT_ATSC_SEC_LEN , "SUB_ATSC_ADDR");
	print_buffer_range(__MM_SUB_PB_START_ADDR,__MM_SUB_PB_LEN , "SUB_PB_START ");
	print_buffer_range(__MM_SUB_HW_DATA_ADDR,__MM_SUB_HW_DATA_LEN , "__MM_SUB_HW_DATA_ADDR ");
	print_buffer_range(__MM_SUB_BS_START_ADDR,__MM_SUB_BS_LEN , "SUB_BS_START_ ");
	print_buffer_range(__MM_OSD_BK_ADDR2, __MM_OSD1_LEN, "__MM_OSD_BK_ADDR2 ");
	print_buffer_range(AVC_LAF_FLAG_BUF_ADDR, AVC_LAF_FLAG_BUF_LEN, "AVC_LAF_FLAG_BUF_ADDR ");
	print_buffer_range(AVC_CMD_QUEUE_ADDR, AVC_CMD_QUEUE_LEN, "AVC_CMD_QUEUE_ADDR ");
#ifdef DUAL_ENABLE
	print_buffer_range(__MM_SEE_MP_BUF_ADDR,__MM_SEE_MP_BUF_LEN , " __MM_SEE_MP_BUF_ADDR");
#endif	
	print_buffer_range(__MM_TTX_PB_START_ADDR, __MM_TTX_PB_LEN, "TTX_PB_START ");
	print_buffer_range(__MM_TTX_BS_START_ADDR, __MM_TTX_BS_LEN, "TTX_BS_START ");
	print_buffer_range(__MM_TTX_P26_DATA_BUF_ADDR, __MM_TTX_P26_DATA_LEN, "TTX_P26_DATA_ ");
	print_buffer_range(__MM_TTX_P26_NATION_BUF_ADDR,__MM_TTX_P26_NATION_LEN , " TTX_P26_NATION");
	print_buffer_range(__MM_TTX_SUB_PAGE_BUF_ADDR, __MM_TTX_SUB_PAGE_LEN, "TTX_SUB_PAGE ");
	print_buffer_range(__MM_DMX_SEE_BLK_ADDR,__MM_DMX_BLK_BUF_LEN , "__MM_DMX_SEE_BLK_ADDR ");
	print_buffer_range(AVC_VBV_ADDR,AVC_VBV_LEN , "AVC_VBV_ADDR ");
	print_buffer_range(__MM_VBV_START_ADDR,__MM_VBV_LEN , "__MM_VBV_START_ADDR ");

	libc_printf("\n\nshare memory mapping\n\n");
#ifdef DUAL_ENABLE
	print_buffer_range(__MM_SHARE_BASE_ADDR,__MM_SHARED_MEM_LEN , "__MM_SHARE_BASE_ADDR ");
	print_buffer_range(__MM_VOID_BUFFER_ADDR, __MM_VOID_BUFFER_LEN , "void buffer to customer");
#endif
	print_buffer_range(__MM_HIGHEST_ADDR, 0, "Total Memory");

    print_buffer_range(0, 0, NULL);


	print_buffer_range(__MM_FB0_Y_START_ADDR, __MM_FB0_Y_LEN, "FB0_Y");
	print_buffer_range(__MM_FB0_C_START_ADDR, __MM_FB0_C_LEN, "FB0_C");
	print_buffer_range(__MM_FB1_Y_START_ADDR, __MM_FB1_Y_LEN, "FB1_Y");
	print_buffer_range(__MM_FB1_C_START_ADDR, __MM_FB1_C_LEN, "FB1_C");
	print_buffer_range(__MM_FB2_Y_START_ADDR, __MM_FB2_Y_LEN, "FB2_Y");
	print_buffer_range(__MM_FB2_C_START_ADDR, __MM_FB2_C_LEN, "FB2_C");

	print_buffer_range(__MM_MP_BUFFER_ADDR, __MM_MP_BUFFER_LEN, "MP_BUFF");
	print_buffer_range(__MM_VIDEO_FILE_BUF_ADDR, __MM_VIDEO_FILE_BUF_LEN, "video_file_buff");
	
	libc_printf("SYS_DRAM_SIZE=%d\n", SYS_SDRAM_SIZE);
}
#else
void print_memory_layout_dual()
{
	extern UINT heap_start;
    //UDG_PRINTF("\n======== Memory Layout ==========\n");

	libc_printf("\n\nmain memory mapping\n\n");

    print_buffer_range(0, heap_start, "Code");
    print_buffer_range(heap_start, (__MM_HEAP_TOP_ADDR&0x0fffffff)-(heap_start&0x0fffffff), "Heap");

	print_buffer_range(__MM_CPU_DBG_MEM_ADDR, __MM_DBG_MEM_LEN, "CPU debug buffer ");
    print_buffer_range(__MM_EPG_BUFFER_START ,__MM_EPG_BUFFER_LEN, "EPG_BUFFER ");
	print_buffer_range(__MM_USB_START_ADDR, __MM_USB_DMA_LEN,"USB_START_");
	print_buffer_range(__MM_DMX_CPU_BLK_ADDR, __MM_DMX_BLK_BUF_LEN,"__MM_DMX_CPU_BLK_ADDR");

	print_buffer_range(__MM_LWIP_MEMP_ADDR, __MM_LWIP_MEMP_LEN,"__MM_LWIP_MEMP_ADDR");
	print_buffer_range(__MM_LWIP_MEM_ADDR, __MM_LWIP_MEM_LEN,"__MM_LWIP_MEM_ADDR");
	print_buffer_range(__MM_AUTOSCAN_DB_BUFFER_ADDR, __MM_AUTOSCAN_DB_BUFFER_LEN,"__MM_AUTOSCAN_DB_BUFFER_ADDR");	
	print_buffer_range(__MM_OSD_VSRC_MEM_ADDR, OSD_VSRC_MEM_MAX_SIZE, "__MM_OSD_VSRC_MEM_ADDR ");
	print_buffer_range(__MM_VCAP_FB_ADDR, __MM_VCAP_FB_SIZE, "__MM_VCAP_FB_ADDR ");
	print_buffer_range(__MM_OSD_BK_ADDR1, __MM_OSD1_LEN, "__MM_OSD_BK_ADDR1 ");
	print_buffer_range(__MM_GE_START_ADDR, __MM_GE_LEN, "__MM_GE_START_ADDR ");	
	print_buffer_range(__MM_PVR_VOB_BUFFER_ADDR,__MM_PVR_VOB_BUFFER_LEN , "VOB cache");
	print_buffer_range(__MM_DMX_REC_START_ADDR, __MM_DMX_REC_LEN,"__MM_DMX_REC_START_ADDR");
	print_buffer_range(__MM_DMX_AVP_START_ADDR,__MM_SI_VBV_OFFSET + __MM_DMX_DATA_LEN + __MM_DMX_AVP_LEN , "DMX AVP ");
	
	print_buffer_range(AVC_LAF_RW_BUF_ADDR,AVC_LAF_RW_BUF_LEN , "AVC_LAF_RW_BUF_ADDR ");
    print_buffer_range(AVC_MB_NEI_ADDR, AVC_MB_NEI_LEN, "AVC_MB_NEI_ADDR ");
    print_buffer_range(AVC_MB_COL_ADDR, AVC_MB_COL_LEN, " AVC_MB_COL_ADDR");
	print_buffer_range(AVC_MV_ADDR, AVC_MV_LEN, "AVC_MV_ADDR ");
    print_buffer_range(AVC_DVIEW_ADDR,AVC_DVIEW_LEN , "AVC_DVIEW_ADDR ");
	print_buffer_range(AVC_FB_ADDR, AVC_FB_LEN, "AVC_FB_ADDR ");
	print_buffer_range(__MM_FB_TOP_ADDR, 0, "Frame buffer top memory");

	libc_printf("\n\nprivate memory mapping\n\n");
#ifdef DUAL_ENABLE
	print_buffer_range(__MM_SEE_DBG_MEM_ADDR,__MM_DBG_MEM_LEN , "SEE debug");
#endif
	print_buffer_range(__MM_SUB_PB_START_ADDR,__MM_SUB_PB_LEN , "SUB_PB_START ");
	print_buffer_range(__MM_SUB_HW_DATA_ADDR,__MM_SUB_HW_DATA_LEN , "__MM_SUB_HW_DATA_ADDR ");
	print_buffer_range(__MM_SUB_BS_START_ADDR,__MM_SUB_BS_LEN , "SUB_BS_START_ ");
	print_buffer_range(__MM_OSD_BK_ADDR2, __MM_OSD2_LEN, "__MM_OSD_BK_ADDR2 ");
	print_buffer_range(AVC_LAF_FLAG_BUF_ADDR, AVC_LAF_FLAG_BUF_LEN, "AVC_LAF_FLAG_BUF_ADDR ");
	print_buffer_range(AVC_CMD_QUEUE_ADDR, AVC_CMD_QUEUE_LEN, "AVC_CMD_QUEUE_ADDR ");
#ifdef DUAL_ENABLE
	print_buffer_range(__MM_SEE_MP_BUF_ADDR,__MM_SEE_MP_BUF_LEN , " __MM_SEE_MP_BUF_ADDR");
#endif	
	print_buffer_range(__MM_TTX_P26_DATA_BUF_ADDR, __MM_TTX_P26_DATA_LEN, "TTX_P26_DATA_ ");
	print_buffer_range(__MM_TTX_P26_NATION_BUF_ADDR,__MM_TTX_P26_NATION_LEN , " TTX_P26_NATION");
	print_buffer_range(__MM_TTX_SUB_PAGE_BUF_ADDR, __MM_TTX_SUB_PAGE_LEN, "TTX_SUB_PAGE ");
	print_buffer_range(__MM_TTX_PB_START_ADDR, __MM_TTX_PB_LEN, "TTX_PB_START ");
	print_buffer_range(__MM_TTX_BS_START_ADDR, __MM_TTX_BS_LEN, "TTX_BS_START ");
	print_buffer_range(__MM_DMX_SEE_BLK_ADDR,__MM_DMX_BLK_BUF_LEN , "__MM_DMX_SEE_BLK_ADDR ");
	print_buffer_range(AVC_VBV_ADDR,AVC_VBV_LEN , "AVC_VBV_ADDR ");
	print_buffer_range(__MM_VBV_START_ADDR,__MM_VBV_LEN , "__MM_VBV_START_ADDR ");

	libc_printf("\n\nshare memory mapping\n\n");
#ifdef DUAL_ENABLE
	print_buffer_range(__MM_SHARE_BASE_ADDR,__MM_SHARED_MEM_LEN , "__MM_SHARE_BASE_ADDR ");
	print_buffer_range(__MM_VOID_BUFFER_ADDR, __MM_VOID_BUFFER_LEN , "void buffer to customer");
#endif
	print_buffer_range(__MM_HIGHEST_ADDR, 0, "Total Memory");

    print_buffer_range(0, 0, NULL);
	
}
#endif
#endif
#endif


#endif

#if SUPPORT_AUTO_TEST
static BOOL m_fAutoTest = FALSE;
static UINT32 m_dwStartTime, m_dwDuration;

static void SetTimeStamp(UINT32 ts)
{
    m_dwStartTime = ts;
    m_dwDuration = ((ts/10)%10 + 1)*50;
}

void SwitchAutoTest()
{
    m_fAutoTest = m_fAutoTest ? FALSE : TRUE;
    if(m_fAutoTest)
        SetTimeStamp(OS_GetTickCount());
}

void AutoTestGenerator()
{
    UINT32 ts, code = NULL_VKEY;

    if(m_fAutoTest)
    {
        ts = OS_GetTickCount();
        if((ts - m_dwStartTime) < m_dwDuration)
            return;
        switch(ts%10)
        {
            case 0:
            case 6:
                code = V_KEY_UP;
                break;
            case 1:
            case 7:
                code = V_KEY_DOWN;
                break;
            case 2:
            case 8:
                code = V_KEY_1;
                break;
            case 3:
            case 9:
                code = V_KEY_1;//2;
                break;
            case 4:
                code = V_KEY_FAV;//V_KEY_P_UP;
                break;
//            case 5:
//                code = V_KEY_P_DOWN;
//                break;
            default:
                break;
        }
        if(NULL_VKEY != code)
            FW_SendMsgToUI(CTL_MSG_TYPE_KEY, CTRL_MSG_SUBTYPE_KEY_IR, code);
        SetTimeStamp(ts);
    }
}

BOOL ComUniStrCmpN(PCWSTR pStr1, PCWSTR pStr2, UINT16 nLen)
{
    UINT16 i, tmp;

    if(NULL == pStr1 || NULL == pStr2)
    	return FALSE;
    if(!nLen)
    {
        nLen = ComUniStrLen(pStr1);
        tmp = ComUniStrLen(pStr2);
        if(nLen != tmp)
            return FALSE;
    }

    for (i=0; i<nLen; i++)
    {
        if(pStr1[i] != pStr2[i])
            return FALSE;
    }
    return TRUE;
}

#endif

#if DBG_COUNTRY_BAND
void print_country_band()
{
#define MAX_REGION      20
#define MAX_BAND_NUMBER 10
typedef Band_param      REGION_BAND[MAX_BAND_NUMBER];
    unsigned long chid = CHID_COUNTRYBAND;
    REGION_BAND *band;
    Band_param *param;
    int i, j;

    band = (REGION_BAND *)(chunk_goto(&chid, 0xFFFFFFFF, 1) + 128);
    for(i=0; i<MAX_REGION; i++)
    {
        param = (Band_param *)band[i];
        if(param->start_freq)
            UDG_PRINTF("======== Region[%d]=0x%x ========\n", i, param);
        for(j=0; j<MAX_BAND_NUMBER && param->start_freq; j++, param++)
        {
            UDG_PRINTF("[%d]%d, %d, %d, %d, %d, %d\n", j, 
                    param->start_freq, param->end_freq, param->bandwidth, 
                    (param->band_type&0x80)?1:0, param->band_type&0x7f, (param->band_type>>8)&0xFF);
        }
    }
}
#endif


#if DBG_WATCH_POINT 
// set watch point for m3501
#
# void sys_set_watch_point(UINT32 addr)
#
		.globl	sys_set_watch_point
        .ent    sys_set_watch_point
sys_set_watch_point:
		mtc0	a0, $18
		nop
		jr      ra
        nop
		.end	sys_set_watch_point


// mask = bit0:store, bit1:load, bit2:fetch
void dbg_set_watch_point(UINT32 addr, UINT32 mask)
{
    addr &= 0xfffffff8;
    addr |= mask;
    sys_set_watch_point(addr);
}

#if 0
//#set watch point for s3602
	asm volatile("; \
		addiu	$8, $29, 36; \
		or $8, $8, 0x1; \
		.word	0x40800000|(8<<16)|(18<<11)|0x02;\
		nop;");
#endif

#endif
